package com.word;

public class Student {
    private String sno;   //学生学号
    private String sname;  //学生姓名
    private int math;   //数学
    private int chinese; //语文

    //设置一个计数器
    private static int count = 0;

    public Student(String sno, String sname, int math, int chinese) {   //有参构造方法
        this.sno = sno;
        this.sname = sname;
        this.math = math;
        this.chinese = chinese;
        //只要创建对象就++
        count++;
    }

    public String getSno() {
        return sno;
    }

    public void setSno(String sno) {
        this.sno = sno;
    }

    public String getSname() {
        return sname;
    }

    public void setSname(String sname) {
        this.sname = sname;
    }

    public int getMath() {
        return math;
    }

    public void setMath(int math) {
        this.math = math;
    }

    public int getChinese() {
        return chinese;
    }

    public void setChinese(int chinese) {
        this.chinese = chinese;
    }

    //获取语总分的方法
    public int getTotalScore() {
        return math + chinese;
    }
    //输出所有学生的信息的方法
    public static void printStudents (Student[] students) {
        for (Student student : students) {
            System.out.println("学号: " + student.getSno() + "，姓名: "+student.getSname() + "，数学: "+student.getMath() + "，语文: "+student.getChinese());
        }
    }

    public static void showMaxTotal(Student[] students) {
        int maxTotalScore = 0;
        Student maxTotalStudent = null;
        for (Student student: students) {
            if (student.getTotalScore() > maxTotalScore) {
                maxTotalScore = student.getTotalScore();
                maxTotalStudent = student;
            }
        }
        System.out.println("总分最高是: "+ maxTotalStudent.getSno() + "," + maxTotalStudent.getSname() + "," + maxTotalStudent.getTotalScore());
    }



    public static void main(String[] args) {
        //实例化三个对象
        Student student1 = new Student("202011101","jack",98,88);
        Student student2 = new Student("202011102","tom",83,95);
        Student student3 = new Student("202011103","lucy",92,78);
        //创建一个对象数组
        Student[] students = {student1,student2,student3};
        System.out.println("当前创建对象个数: " + count);
        printStudents(students);
       //找出总分最高的学生
        showMaxTotal(students);
    }
}
